import datetime

from utils import restful
from .serializers import *


# 搜索机票
def get_flight_info(request):
    from_place = request.GET.get('from_place')
    to_place = request.GET.get('to_place')
    departure_day = request.GET.get('departure_day', '')
    if departure_day == '':
        departure_day = datetime.datetime.now()
    return_day = request.GET.get('return_day', '')
    result = RouteInfo.objects.filter(from_place=from_place, to_place=to_place, start_time__gt=departure_day)
    data = RouteInfoSerializer(result, many=True).data

    return restful.ok(data=data)


# 获取精选推荐
def get_recommend_flight(request):
    result = RouteInfo.objects.filter(start_time__gt=datetime.datetime.now())
    data = RouteInfoSerializer(result, many=True).data

    return restful.ok(data=data)
